var httpsUrl = getApp().globalData.httpsUrl;
var globalData = getApp().globalData;
var commonUtil = require("../../../utils/commonUtil.js")
Page({

  data: {
    imgUrl: globalData.imgUrl,
    username:'',
    password:'',
  },
  loadDate: function () {
    let username = wx.getStorageSync("username");
    let password = wx.getStorageSync("password");
    this.setData({username: username,password: password})
  },
  login: function () {
    var params = new Object();
    params.username = this.data.username;
    params.password = this.data.password;
    if (commonUtil.isEmpty(params.username)) {
      commonUtil.showModal("请输入手机号");
      return;
    }
    if (commonUtil.isEmpty(params.password)) {
      commonUtil.showModal("请输入密码");
      return;
    }
    let that = this;
    commonUtil.showLoading("请稍等...");
    let openId = wx.getStorageSync("openidKey");
    console.log("param:"+JSON.stringify(params));
    wx.request({
      header: { "openId": openId},
      url: httpsUrl + "/businessManage/login",
      dataType: "json",
      method: "POST",
      data: params,
      success: function (result) {
        commonUtil.hideLoading();
        console.log(JSON.stringify(result));
        var res = result.data;
        if (res.result == 0) {
          commonUtil.showSuccessToast("登录成功");
          wx.setStorageSync("username", params.username);
          wx.setStorageSync("password", params.password);
          let JSESSIONID = res.data;
          wx.setStorageSync("JSESSIONID", JSESSIONID);
          that.shopUser();
        } else {
          commonUtil.showModal(res.msg);
        }
      }
    })
  },

  username: function (e) {
    this.setData({username: e.detail.value})
  },

  password: function (e) {
    this.setData({password: e.detail.value})
  },
  shopAdd:function(){
    wx.navigateTo({
      url: '../shopAdd/shopAdd',
    })
  },
  shopUser:function(){
    wx.navigateTo({
      url: '../shopUser/shopUser',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadDate();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.loadDate();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})